<template>
  <div class="execution">
    <basic-container>
      <el-card class="filter-container" shadow="never">
        <div style="margin-top: 10px">
          <el-form :inline="true" size="small" label-width="140px">
            <el-form-item label="提现账号：">
              <el-input
                style="width: 203px"
                v-model="alipayPhone"
                placeholder="请输入~"
              ></el-input>
            </el-form-item>

            <el-form-item>
              <el-button @click="getList" type="primary" size="small"
                >查询结果</el-button>
              <el-button @click="handleResetSearch" size="small">
                重置
              </el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-card>
      <div class="table-container">
        <el-table
            border
            :data="list"
            :header-cell-style="{ color: '#4D4D4D', background: '#fafafa' }">
            <el-table-column label="操作时间" min-width="100" align="center">
              <template slot-scope="scope">
                {{ scope.row.updateTime }}
              </template>
            </el-table-column>

            <el-table-column label="收款账号" min-width="100" align="center">
              <template slot-scope="scope">
                {{ scope.row.alipayPhone }}
              </template>
            </el-table-column>

            <el-table-column label="申请金额" min-width="100" align="center" prop="productType">
              <template slot-scope="scope">
                {{ scope.row.depositAmount }}
              </template>
            </el-table-column>

            <el-table-column label="申请状态" min-width="100" align="center" prop="productType">
              <template slot-scope="scope">
                {{ scope.row.type | Type }}
              </template>
            </el-table-column>

            <el-table-column label="驳回原因"   min-width="100" align="center" prop="useGift">
              <template  slot-scope="scope" v-if="scope.row.productType === 2">
                ￥{{ scope.row.reason }}
              </template>
            </el-table-column>

            <el-table-column label="操作人"  min-width="100" align="center" prop="useGift">
              <template slot-scope="scope">
                {{ scope.row.operationName}}
              </template>
            </el-table-column>
            <el-table-column label="会员Id" min-width="100" align="center">
              <template slot-scope="scope">
                {{ scope.row.memberId }}
              </template>
            </el-table-column>
            <el-table-column label="操作" min-width="150">
              <template slot-scope="scope">
                <el-button
                    v-if="scope.row.type === 1 || scope.row.type === 2"
                    size="small"
                    @click="handleExamine(scope.$index, scope.row)"
                    type="text"
                    plain
                    >审核
                  </el-button>
              </template>
            </el-table-column>
          </el-table>
      </div>
      <div class="pagination-container">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          layout="total, sizes,prev, pager, next,jumper"
          :page-size="listQuery.size"
          :page-sizes="[5, 10, 15]"
          :current-page.sync="listQuery.current"
          :total="total"
        >
        </el-pagination>
      </div>

      <el-dialog title="审核" :visible.sync="dialogVisible" width="50%">
      <el-form :model="review" ref="review"  label-width="150px">
        <el-form-item label="手机号码：">
          <el-input v-model="review.alipayPhone" disabled></el-input>
        </el-form-item>
        <el-form-item label="申请金额：">
          <el-input v-model="review.depositAmount" disabled></el-input>
        </el-form-item>
        <el-form-item label="申请状态：">
          <el-radio-group v-model="review.type">
            <el-radio :label="3">通过</el-radio>
            <el-radio :label="4">驳回</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="驳回原因：" v-if="review.type == 4">
          <el-input
            type="textarea"
            :rows="2"
            placeholder="请输入内容"
            v-model="review.reason">
          </el-input>
        </el-form-item>
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="handleConfirm('review')"
            >确 定</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog>
    </basic-container>
  </div>
</template>

<script>
import { listMemberDepositDtl, reviewAmount } from "@/api/wdrawal/index";
const defaultListQuery = {
  current: 1,
  size: 10,
}
export default {
  data() {
    return {
      list: [],
      total: 0,
      listQuery: {
        current: 1,
        size: 10,
      },
      dialogVisible: false,
      review: {
        id: null,
        memberId: null,
        type: 3,
        reason: null,
        alipayPhone: null,
        depositAmount: null
      },

      alipayPhone: null

    }
  },
  created() {
    this.getList()
  },
  filters: {
    Type(val) {
      if (val === 1) {
        return "未申请";
      } else if (val === 2) {
        return "已申请";
      } else if (val === 3) {
        return "已通过";
      } else if (val === 4) {
        return "已驳回";
      }
    },
  },
  methods: {
    handleSizeChange(val) {
      this.listQuery.size = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.current = val;
      this.getList();
    },
    handleResetSearch() {
      this.alipayPhone = null;
      this.listQuery = Object.assign({}, defaultListQuery);
       this.getList();
    },
    getList() {
      if(this.alipayPhone) {
        this.listQuery.alipayPhone = this.alipayPhone
      }
      listMemberDepositDtl(this.listQuery).then((res) => {
        this.list = res.data.data.records;
        this.total = res.data.data.total;
      });
    },
    handleExamine(index,row) {
      this.dialogVisible = true;
      this.review.id = row.id;
      this.review.memberId = row.memberId,
      this.review.alipayPhone = row.alipayPhone,
      this.review.depositAmount = row.depositAmount
    },
    handleConfirm(review) {
      if(this.review.type == 4) {
        if(!this.review.reason) {
          this.$message({
              message: "请填写驳回原因~",
              type: 'warning',
              duration: 1000
          });
          return;
        }
      }
      reviewAmount(this.review).then(res => {
        if (res.data.code === 200) {
            this.$message({
              message: res.data.msg,
              type: 'success',
              duration: 1000
            });
            this.dialogVisible = false;
            this.getList();
          } else {
            this.$message({
              message: res.data.msg,
              type: 'warning',
              duration: 1000
            });
          }
      })
    }
  }
};
</script>

<style>
</style>
